package net.tngou.tnfs.action;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;

import net.tngou.tnfs.jdbc.OrderType;
import net.tngou.tnfs.pojo.Gallery;
import net.tngou.tnfs.pojo.Galleryclass;
import net.tngou.tnfs.util.PageUtil;


public class IndexAction extends BaseAction {

	

	
	@Override
	public void execute() throws ServletException, IOException {
		int page= request.getParameter("p")==null?1:Integer.parseInt(request.getParameter("p"));
		List<?> galleryclasses = baseService.getList("seq",OrderType.ASC,Galleryclass.class);	
		root.put("galleryclasses", galleryclasses);
		
		String[] params = request.getParams();
		if(params==null)
		{
			PageUtil pageUtil = baseService.getPage(page, 20,  Gallery.class);
			root.put("page", pageUtil);	
		}else
		{
			Galleryclass galleryclass = new Galleryclass().get(Long.parseLong(params[0]));
			String filter="1=1";
			if(galleryclass!=null)filter="galleryclass="+galleryclass.getId();
			PageUtil pageUtil = baseService.getPage(page, 20, filter, Gallery.class);
			root.put("page", pageUtil);	
			root.put("galleryclass", galleryclass);
		}
		
	
		printFreemarker("default/index.ftl", root);
	}
}
